﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style type="text/css">
    /*.step-content {
        min-height: 320px !important;
    }*/
</style>

<form id="form1">
    <div class="formDiv">
        <div class="widget-body">
            <div id="wizard" class="wizard" data-target="#wizard-steps" style="border-left: none; border-top: none; border-right: none;">
                <ul class="steps">
                    <li data-target="#step-1" class="active"><span class="step">1</span>系统功能<span class="chevron"></span></li>
                    <li data-target="#step-2"><span class="step">2</span>系统按钮<span class="chevron"></span></li>

                </ul>
            </div>
            <div class="step-content" id="wizard-steps" style="border-left: none; border-bottom: none; border-right: none;">
                <div class="step-pane active" id="step-1" style="margin-left: 0px; margin-top: 0px; margin-right: 30px;">
                    <table class="form">
                        <tr>
                            <th class="formTitle">归属组织</th>
                            <td class="formValue">
                                <select id="OrganizeId" name="OrganizeId" class="form-control" isvalid="yes" checkexpession="NotNull"></select>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">角色名称</th>
                            <td class="formValue">
                                <input id="FullName" name="FullName" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">角色编号</th>
                            <td class="formValue">
                                <input id="EnCode" name="EnCode" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">角色类型</th>
                            <td class="formValue">
                                <select id="Type" name="Type" class="form-control"></select>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">显示顺序</th>
                            <td class="formValue">
                                <input id="SortCode" name="SortCode" type="text" class="form-control" isvalid="yes" checkexpession="Num" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" style="height: 35px;">选项</th>
                            <td class="formValue" style="padding-top: 1px;">
                                <div class="checkbox user-select">
                                    <label>
                                        <input id="AllowEdit" name="AllowEdit" type="checkbox" />
                                        允许编辑
                                    </label>
                                    <label>
                                        <input id="AllowDelete" name="AllowDelete" type="checkbox" />
                                        允许删除
                                    </label>
                                    <label>
                                        <input id="EnabledMark" name="EnabledMark" type="checkbox" checked="checked" />
                                        有效
                                    </label>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" valign="top" style="padding-top: 5px;">
                                备注
                            </th>
                            <td class="formValue">
                                <textarea id="Description" name="Description" class="form-control" style="height: 60px;"></textarea>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="step-pane modulebtn" id="step-2">
                    <div id="permissionTree"></div>
                </div>

            </div>
        </div>
        <div class="form-button" id="wizard-actions" style="right:0px;">
            <a id="btn_last" disabled class="btn btn-default btn-prev">上一步</a>
            <a id="btn_next" class="btn btn-default btn-next">下一步</a>
            <a id="btn_finish" disabled class="btn btn-success">完成</a>
        </div>


    </div>

</form>
<script type="text/javascript">
    var keyValue = $.fn.request("keyValue");
    $(function () {
        initControl();
        if (!!keyValue) {
            $.fn.setForm({
                url: "/SystemManage/Role/GetFormJson",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data);
                }
            });
        }
    })
    function initControl() {
        $("#OrganizeId").bindSelect({
            url: "/SystemManage/Organize/GetTreeSelectJson",
        });

        $("#Type").bindSelect({
            url: "/SystemManage/ItemsData/GetSelectJson",
            param: { enCode: "RoleType" }
        });
        //加载权限配置
        $("#permissionTree").treeview({
            height: 360,
            showcheck: true,
            url: "/SystemManage/RoleAuthorize/GetPermissionTree",
            param: { roleId: keyValue }
        });
    }
    //下一步
    $("#btn_next").click(function () {
        if (!$('#form1').Validform()) {
            return false;
        } else {
            $(this).attr("disabled", "").siblings().removeAttr("disabled");
            $(".steps li:eq(0)").attr("class", "complete").next().addClass("active");
            $("#step-1").removeClass("active").next().addClass("active");
        }
    })
    //上一步
    $("#btn_last").click(function () {
        $(this).attr("disabled", "").next().removeAttr("disabled").next().attr("disabled", "");
        $(".steps li:eq(1)").removeClass("active").prev().attr("class", "active");
        $("#step-2").removeClass("active").prev().addClass("active");
    })
    //提交表单
    $("#btn_finish").click(function () {
        if ($(this).attr("disabled") == 'disabled') {
            return false;
        }
        if (!$('#form1').Validform()) {
            return false;
        } else {
            var data = $("#form1").GetWebControls();
            data["permissionIds"] = String($("#permissionTree").getCheckedAllNodes());
            $.fn.submitForm({
                url: "/SystemManage/Role/SubmitForm?keyValue=" + keyValue,
                param: data,
                loading: "正在保存数据...",
                success: function () {
                    $.currentIframe().$("#gridTable").trigger("reloadGrid");
                }
            });
        }
    })
</script>